package com.ruoyi.chat.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RedisUtil {
    private final RedisTemplate<Object, Object> redisTemplate;

    @Autowired
    public RedisUtil(RedisTemplate<Object, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    public List<Object> get(String key) {
        // 从左到右获取所有元素
        return redisTemplate.opsForList().range(key, 0, -1);
    }

    public void set(String key, Object value) {
        // 从右到左插入元素
        redisTemplate.opsForList().rightPush(key, value);
    }

}
